layui.use([ 'form', 'layer' ], function() {
			$ = layui.jquery;
			var form = layui.form, layer = layui.layer;

			//自定义验证规则
			form.verify({
				nikename : function(value) {
					if (value.length < 5) {
						return '账号至少得5个字符啊';
					}
				},
				pass : [ /(.+){6,12}$/, '密码必须6到12位' ],
				repass : function(value) {
					if ($('#L_pass').val() != $('#L_repass').val()) {
						return '两次密码不一致';
					}
				}
			});

			//监听提交
			form.on('submit(add)', function(data) {
				console.log(data);
				console.log(data);
				var arr = new Array();
				var arr2 = new Array();
				$("input:checkbox[name='checkbox2']:checked").each(function(i) {
					arr[i] = $(this).val();
				});
				$("input:checkbox[name='checkbox1']:checked").each(function(i) {
					arr2[i] = $(this).val();
				});
				data.field.checkbox2 = arr.join(",");//将数组合并成字符串
				data.field.checkbox1 = arr2.join(",");//将数组合并成字符串
				console.log(data.field.checkbox1);
				console.log(data.field.checkbox2);
				$.post("addedMembershipPrivileges.do", {
					pMainId : data.field.checkbox1,
					pSubId : data.field.checkbox2,
					aUsername : data.field.username,
					aPassword : data.field.pass
				}, function(res) {
					if (res.type == 1) {
						layer.alert("添加成功", {
							icon : 6
						},
								function() {
									// 获得frame索引
									var index = parent.layer
											.getFrameIndex(window.name);
									//关闭当前frame
									parent.layer.close(index);
									window.location.reload();
								});
					} else {
						window.location.reload();
						layer.msg(data.msg, {
							area : [ '300px', '200px' ]
						});
					}
				}, "json")
				return false;
			});
			
			menu();
    		sub();
    	function menu(){
			$.post("menu.do",function(data){
				var html="";
    			for (var i = 0; i < data.data.length; i++) {
					html+='<input type="checkbox" name="checkbox1" title='+data.data[i].mNames+' value='+data.data[i].mId+'>';
				}
    	
    			$("#menusub").html(html);
    	
    			layui.form.render();
    		},"json")
    	}
    	
    	function sub(){
			$.post("sub.do",function(data){
				var html="";
    			for (var i = 0; i < data.data.length; i++) {
					html+=" <input type='checkbox' name='checkbox2' title="+data.data[i].sPathName+" value="+data.data[i].sId+">";
				}
    			$("#sub").html(html);
    			layui.form.render();
    		},"json")
    	}

		});